// 差分 时间复杂度O(n + m)；空间复杂度O(1)

class Solution {
public:
    vector<int> corpFlightBookings(vector<vector<int>>& bookings, int n) {
        vector<int> ret(n, 0);
        for (auto& row: bookings) {
            ret[row[0] - 1] += row[2];
            if (row[1] < n) {
                ret[row[1]] -= row[2];
            } 
        }
        for (int i = 1; i < n; i++) {
            ret[i] += ret[i - 1];
        }
        return ret;
    }
};